<?php
ini_set("display_errors" ,1);
my_component_load('xl_builder' , false);
my_component_load('testing' , false);
my_component_load('paging' , false);  
my_component_load('pr_formula_gaji' , false);  
my_component_load('list_kalender' , false);    
my_component_load('pr_adjustment' );
$task = isset($_GET['task']) ? $_GET['task'] : ""; 
$karyawan_id= isset( $_GET['karyawan_id'] ) ? $_GET['karyawan_id']:  0;
$komponen_id= isset( $_GET['komponen_id'] ) ? $_GET['komponen_id']:  0;
$komponen_id1= isset( $_GET['komponen_id1'] ) ? $_GET['komponen_id1']:  0;

$modulname = "Penggajian _BN_ Proses _BN_ Kalkulasi";
if(isset($_GET['excel'])){

header("Content-Type: application/xls");;
header("Content-Disposition: attachment;filename=kalkulasi_".rand().".xls");
	echo list_excel();
	exit;
}else{
	if($_SERVER["REQUEST_METHOD"] == "POST" ){
		if($task == 'edit_penyesuaian_page'){
			submit_penyesuaian($karyawan_id , $komponen_id);
			$content = "Updated!";
			generate_my_web($content , $pagename ,'plain.php');
			exit;
		}
	}else{
		if($task =='detail'){
			$pagename = $modulname." _BN_ Detail";
			load_facebox_script();
			$view =  list_adjustment_detail($karyawan_id);
		}elseif($task =='rinci'){
			$pagename = $modulname." _BN_ Perincian Komponen";
			load_facebox_script();
			$view =  list_rinci_pajak($karyawan_id,$komponen_id);
		}elseif($task =='pajak'){
			$pagename = $modulname." _BN_ Pajak";
			load_facebox_script();
			$view =  list_kalkulasi_pajak($karyawan_id);		
		}elseif($task =='kalkulasi_gaji'){
			$query = "DELETE FROM pr_gaji_komponen 
				WHERE karyawan_id ={$karyawan_id} 
				AND periode_id=0";
			$result = my_query($query); //reset
			$query = "DELETE FROM pr_gaji_pajak 
				WHERE karyawan_id ={$karyawan_id} 
				AND periode_id=0";
			$result = my_query($query); //reset
			$konstan=get_konstan();
			kalkulasi_gaji($karyawan_id, $konstan) ;
			my_direct($_SERVER['HTTP_REFERER']);	
// 	tombol kalkulasi -> kgs ->kalkulasi_gaji_all_page ->page(kalkulasi) -> kalkulasi_gaji_all -> kalkulasi_gaji
//	tombol kalkulasi per karyawan ->kalkulasi_gaji
	//ADD LOADING		
		}elseif($task =='kga'){
			$title="Kalkulasi gaji seluruh karyawan";
			facebox_page('index.php?com='.$_GET['com'].'&task=kalkulasi_gaji_all_page&p='.rand(0,999999) , $title , 120	); 
		}elseif($task =='kalkulasi_gaji_all_page'){
			$content = page_kalkulasi(); 
			generate_my_web($content,"","plain.php");
			exit;
	//END ADD LOADING		
			
		}elseif($task =='kalkulasi_gaji_all'){
			ini_set("max_execution_time","10000");
			header("Cache-Control: no-cache, must-revalidate");
			$query = "UPDATE opsi_seting SET value='{$_SESSION['user_id']}' WHERE name='kalkulasi'";
			my_query($query);
			kalkulasi_gaji_all() ;
			$query = "UPDATE opsi_seting SET value='0' WHERE name='kalkulasi'";
			my_query($query);
			echo button_icon( 'check2.png' ,'')."<br/>Done !!";
			exit;
			//my_direct($_SERVER['HTTP_REFERER']);		
		}elseif($task == 'edit_penyesuaian'){
				$title=  "Penyesuaian nominal"  ;
				facebox_page('index.php?com=pr_adjustment&task=edit_penyesuaian_page&komponen_id='.$komponen_id.'&karyawan_id='.$karyawan_id.'&id='.$id , $title , 245	); 
		}elseif($task == 'edit_penyesuaian_page'){
			$pagename="";
			$content = form_penyesuaian($karyawan_id , $komponen_id);
			generate_my_web($content , $pagename ,'plain.php');
			exit; 
		}elseif($task =='thp_minus'){
			$pagename = $modulname." _BN_ Take Home Pay Minus";
			load_facebox_script();	
			$view = thp_minus();
		}else{
			$pagename = $modulname ;
			load_facebox_script();	
			$view = list_adjustment();
		}
	}	
}	
generate_my_web($view, $pagename );

?>

